//
//  fenLeiDetailViewController.m
//  Experss
//
//  Created by wmwMAC on 17/7/31.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "fenLeiDetailViewController.h"

#import "FenLeiDetailSearchHomeView.h"//搜索条
#import "TitleView.h"//选择条

#import "GoodsListTableViewCell.h"
#import "GoodsListCollectionViewCell.h"

#import "FenLeiDetailZongheView.h"//综合
#import "fenLeiDetailShaiXuanView.h"//筛选

#import "FenLeiDDetailViewController.h"

#import "FenleiShaixuanModel.h"
#import "FenleiShaixuanSmallModel.h"
#import "FenLeiDetaileModle.h"

static NSString *identifierForGoodsListTableViewCell = @"GoodsListTableViewCell";
static NSString *identifierForGoodsListCollectionViewCell = @"GoodsListCollectionViewCell";
#define kSelectViewHeight 50
@interface fenLeiDetailViewController () <FenLeiDetailSearchHomeViewdelegate,TitleViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource,FenLeiDetailZongheViewDelegate,fenLeiDetailShaiXuanDelegate,UITextFieldDelegate>
{
    //搜索条
    FenLeiDetailSearchHomeView *searchView;
    //
    NSInteger _page;
    NSString *xiaoliangType;
    NSString *jiageType;
//    NSString *brandIdStr;
//    NSString *min_price;
//    NSString *max_price;
    
    //
    NSMutableDictionary *parameDic;
}

/** selectView */
@property (nonatomic , strong) TitleView *selectTitleView;
/** tableView */
@property (nonatomic , strong) UITableView *tableView;
/** collectionView */
@property (nonatomic , strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) NSMutableArray *dataArr22;

@property (nonatomic , strong) FenLeiDetailZongheView *FenLeiview;

@property (nonatomic , strong) fenLeiDetailShaiXuanView *shaiXuanView;//筛选view
@property (nonatomic, strong) NSArray *tempSXArr;

@end

@implementation fenLeiDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];

    _dataArr = [NSMutableArray array];
   _dataArr22 = [NSMutableArray array];
    
    _tempSXArr = [NSArray array];
    _page = 1;
    xiaoliangType = @"1";
    jiageType = @"1";
    
    parameDic = [NSMutableDictionary dictionary];


    [self addTitleUI];
    [self createCollectionView];
    [self createTableView];

    

    [self GetScreenData];
    [self GetGoodslist];


}



#pragma mark    -------------- 搜索条 --------------
-(void)addTitleUI{
    self.selectTitleView = [[TitleView alloc] initSelectViewWithFrame:CGRectMake(0, 0, kScreen_Width, kSelectViewHeight)];
    self.selectTitleView.backgroundColor = [UIColor whiteColor];
    self.selectTitleView.delegate = self;
 
    [self.view addSubview:self.selectTitleView];
}
-(void)xiaoliang{//是否销量排序 2倒序 1正序
    if ([xiaoliangType isEqualToString:@"1"]) {
        xiaoliangType = @"2";
    }else{
        xiaoliangType = @"1";
    }
    
    
    [parameDic setObject:xiaoliangType forKey:@"is_sale"];
    [parameDic removeObjectForKey:@"whole"];
    [parameDic removeObjectForKey:@"is_price"];
    [self GetGoodslist];
    
    
    NSLog(@"xiaoliang");
}
-(void)jiage{//是否价格排序 2倒序 1正序
    NSLog(@"jiage");
    if ([jiageType isEqualToString:@"1"]) {
        jiageType = @"2";
    }else{
    
        jiageType = @"1";
    }
    [parameDic setObject:jiageType forKey:@"is_price"];
    [parameDic removeObjectForKey:@"whole"];
    [parameDic removeObjectForKey:@"is_sale"];
    [self GetGoodslist];
}
-(void)zonghe:(NSString *)zhongheType{
    NSLog(@"zonghe");
    
    // 弹出一个View 背景半透明   tableView
    
    // 封装起来  代理 回调 选了哪一个
    
    if (_FenLeiview == nil) {
        _FenLeiview = [FenLeiDetailZongheView initWithFenLeiDetailZongheView];
        _FenLeiview.delegate = self;
        _FenLeiview.selectString = zhongheType;
    }
    [self.view addSubview:_FenLeiview];
    
}
- (void)selectTypeWithString:(NSString *)selectString{
    self.selectTitleView.zhongheType = selectString;
    
    
    NSString *zongheType = @"0";//0综合 1促销(最热) 2上线(最新)
    if ([self.selectTitleView.zhongheType isEqualToString:@"最新"]) {
        zongheType = @"2";
    }else if ([self.selectTitleView.zhongheType isEqualToString:@"最热"]){
        zongheType = @"1";
    }
    [parameDic setObject:zongheType forKey:@"whole"];
    [parameDic removeObjectForKey:@"is_price"];
    [parameDic removeObjectForKey:@"is_sale"];
    
    
//    [parameDic setObject:jiageType forKey:@""];
    [self GetGoodslist];
}

- (void)selectView:(TitleView *)selectView changeBtn:(UIButton *)changeBtn{
    NSLog(@"筛选");
    _shaiXuanView = [[fenLeiDetailShaiXuanView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height)];
    _shaiXuanView.delegate = self;
    
    FenleiShaixuanModel *model1 = [[FenleiShaixuanModel alloc] init];
    
    model1.name = @"品牌";
    model1.type = @"0";
    model1.isopen = NO;
    
//    NSMutableArray *tempArray = [NSMutableArray array];
//    for (NSInteger i = 0; i < 7; i++) {
//        FenleiShaixuanSmallModel *model2 = [[FenleiShaixuanSmallModel alloc] init];
//        
//        model2.title = [NSString stringWithFormat:@"%ld",i+1];
//        model2.did = [NSString stringWithFormat:@"%ld",i+1];
//        
//        [tempArray addObject:model2];
//    }
//    
    model1.brand = _tempSXArr;
//
//    
    FenleiShaixuanModel *model3 = [[FenleiShaixuanModel alloc] init];
    
    model3.name = @"价格";
    model3.type = @"1";
    model3.isopen = NO;
    model3.maxprice = @"";
    model3.minprice = @"";
    
    _shaiXuanView.dataArray = @[model1,model3];
    
    [self.view.window addSubview:_shaiXuanView];
    
}
#pragma mark ------------- 筛选返回数据 ----
-(void)fenLeiDetailShaiXuanBackBrandArr:(NSArray *)BrandArr PriceArr:(NSArray *)priceArr{
    
    // 品牌ID (注意: 多个ID已英文,隔开),例如：1,2,3
    
    
    if (!BrandArr.count && !priceArr.count) {// 重置筛选
        [_selectTitleView.shaixuanJiao setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
        [_selectTitleView.changeBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
        [parameDic removeObjectForKey:@"brand_id"];
        [parameDic removeObjectForKey:@"min_price"];
        [parameDic removeObjectForKey:@"max_price"];

        
    }else{
        NSLog(@"筛选啦");
       NSString *brandIdStr = [BasePublicClass returnStringFromDicOrArray:BrandArr];
        [parameDic setObject:brandIdStr forKey:@"brand_id"];
        
        // 获取价格
        FenleiShaixuanModel *modle2 = _shaiXuanView.dataArray[1];
        if (modle2.maxprice.length) {
            [parameDic setObject:jiageType forKey:@"max_price"];
        }
        if (modle2.minprice.length) {
             [parameDic setObject:jiageType forKey:@"min_price"];
        }
       
        
        
    }
    [self GetGoodslist];
}


- (void)createCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    CGFloat width = (kScreen_Width - 5)/2.0;
    CGFloat height = 255 *(kScreen_Width /375);
    layout.itemSize = CGSizeMake(width, height);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, kSelectViewHeight, kScreen_Width, kScreen_Height - 64 - kSelectViewHeight) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.showsVerticalScrollIndicator = NO;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"GoodsListCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:identifierForGoodsListCollectionViewCell];
    
    
    
    [self.view addSubview:self.collectionView];
    
    
    
    
    
    MJRefreshGifHeader *headNew = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestRefresh)];
    NSMutableArray *refreshingImages2 = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [refreshingImages2 addObject:image];
    }
    
    NSMutableArray *idleImages2 = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [idleImages2 addObject:image];
    }
    // 设置普通状态的动画图片
    [headNew setImages:idleImages2 forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [headNew setImages:refreshingImages2 forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [headNew setImages:refreshingImages2 duration:2 forState:MJRefreshStateRefreshing];
    // 隐藏状态
    headNew.stateLabel.hidden = YES;
    headNew.lastUpdatedTimeLabel.hidden = YES;
    
    self.collectionView.mj_header = headNew;
    
    
    
    
    
    MJRefreshBackGifFooter *_header = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestDtaLoadMore)];
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [refreshingImages addObject:image];
    }
    
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [idleImages addObject:image];
    }
    // 设置普通状态的动画图片
    [_header setImages:idleImages forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [_header setImages:refreshingImages forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [_header setImages:refreshingImages duration:2 forState:MJRefreshStateRefreshing];
    // 隐藏状态
    _header.stateLabel.hidden = YES;
    self.collectionView.mj_footer = _header;
}

#pragma mark －＝－－＝－＝＝－＝＝－＝－－＝＝－collectionview的刷 新,加载事件
- (void) requestRefresh{
    _page = 1;
    [self GetGoodslist];
}
- (void)requestDtaLoadMore {
    _page++;
    [self GetGoodslist];
    
}

- (void)createTableView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kSelectViewHeight, kScreen_Width, kScreen_Height - 64 - kSelectViewHeight) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.showsVerticalScrollIndicator = NO;
    
    self.tableView.rowHeight = 120;
    
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.tableView registerNib:[UINib nibWithNibName:identifierForGoodsListTableViewCell bundle:nil] forCellReuseIdentifier:identifierForGoodsListTableViewCell];
    self.tableView.hidden = YES;
    [self.view addSubview:self.tableView];
    
    
    MJRefreshGifHeader *headNew = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestRefresh)];
    NSMutableArray *refreshingImages2 = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [refreshingImages2 addObject:image];
    }
    
    NSMutableArray *idleImages2 = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [idleImages2 addObject:image];
    }
    // 设置普通状态的动画图片
    [headNew setImages:idleImages2 forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [headNew setImages:refreshingImages2 forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [headNew setImages:refreshingImages2 duration:2 forState:MJRefreshStateRefreshing];
    // 隐藏状态
    headNew.stateLabel.hidden = YES;
    headNew.lastUpdatedTimeLabel.hidden = YES;
    self.tableView.mj_header = headNew;
    
    
    
    
    
    MJRefreshBackGifFooter *_header = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestDtaLoadMore)];
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [refreshingImages addObject:image];
    }
    
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [idleImages addObject:image];
    }
    // 设置普通状态的动画图片
    [_header setImages:idleImages forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [_header setImages:refreshingImages forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [_header setImages:refreshingImages duration:2 forState:MJRefreshStateRefreshing];
    // 隐藏状态
    _header.stateLabel.hidden = YES;
    self.tableView.mj_footer = _header;
}

#pragma mark -- UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArr.count;;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GoodsListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierForGoodsListTableViewCell forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    FenLeiDetaileModle *model = _dataArr[indexPath.section];
    cell.contentLabel.text = model.name;
    cell.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.sell_price];
    cell.salesCountLabel.text = [NSString stringWithFormat:@"¥%@", model.market_price];
    NSString *imgStr = [NSString stringWithFormat:@"%@",model.image];
    
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"quetu"]];
    
    
    [cell.addCarBtn addTarget:self action:@selector(handleAddbuyCarAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    return cell;
}

#pragma mark －＝－＝－＝tableView－＝－商品列表添加到添加到购物车
- (void)handleAddbuyCarAction :(UIButton *)sender {
    
    GoodsListTableViewCell *cell= (GoodsListTableViewCell *)[[sender superview] superview];
    NSIndexPath *indaPath = [self.tableView indexPathForCell:cell];
    FenLeiDetaileModle *model = _dataArr[indaPath.section];
    
    //商品goods_id  sku_id num 为测试数据，应该改为_goodsID ,,,,,
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDicTemp = @{@"userid":saveDic[@"userid"],@"goods_id":[NSString stringWithFormat:@"%@",model.Id],@"sku_id":[NSString stringWithFormat:@"%@",model.sku_id],@"num":[NSString stringWithFormat:@"%@",model.minimum],@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    [HttpRequest postWithURLString:POST(Shop_CartAddCart) parameters:parameDicTemp success:^(id responseObject) {
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"加入购物车失败" timeLength:1.5];
            return ;
        }
        
        [MBProgressHUD showText:@"加入购物车成功"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refshIngShopCar" object:nil];
        
    
        [MBProgressHUD showText:responseObject[@"data"][@"msg"]];
    } failure:^(NSError *error) {
        
    }];
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    FenLeiDetaileModle *model = _dataArr[indexPath.section];
    FenLeiDDetailViewController *vc = [[FenLeiDDetailViewController alloc] init];
    vc.goodsID = model.Id;
    [self.navigationController pushViewController:vc animated:YES];
    
}



#pragma mark -- UICollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GoodsListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierForGoodsListCollectionViewCell forIndexPath:indexPath];
    
    FenLeiDetaileModle *model = _dataArr[indexPath.item];
    cell.contentLabel.text = model.name;
    
    cell.priceLabel.text =  [NSString stringWithFormat:@"¥%@",model.sell_price];
    cell.twoLB.text =[NSString stringWithFormat:@"¥%@", model.market_price];
    NSString *imgStr = [NSString stringWithFormat:@"%@",model.image];
    
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"quetu"]];
    
    [cell.addBuyCarBtn addTarget:self action:@selector(handelAddCarAction:) forControlEvents:(UIControlEventTouchUpInside)];
    return cell;
}
#pragma mark －＝－＝－＝collection－＝－商品列表添加到添加到购物车
- (void)handelAddCarAction :(UIButton *)sender {
    
    GoodsListCollectionViewCell *cell= (GoodsListCollectionViewCell *)[[sender superview] superview];
    NSIndexPath *indaPath = [self.collectionView  indexPathForCell:cell];
    FenLeiDetaileModle *model = _dataArr[indaPath.item];
    
    //商品goods_id  sku_id num 为测试数据，应该改为_goodsID ,,,,,
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDicTemp = @{@"userid":saveDic[@"userid"],@"goods_id":[NSString stringWithFormat:@"%@",model.Id],@"sku_id":[NSString stringWithFormat:@"%@",model.sku_id],@"num":[NSString stringWithFormat:@"%@",model.minimum],@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    [HttpRequest postWithURLString:POST(Shop_CartAddCart) parameters:parameDicTemp success:^(id responseObject) {
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"加入购物车失败" timeLength:1.5];
            return ;
        }
        
        [MBProgressHUD showText:@"加入购物车成功"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refshIngShopCar" object:nil];
        
        
        [MBProgressHUD showText:responseObject[@"data"][@"msg"]];
    } failure:^(NSError *error) {
        
    }];
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%@",indexPath);
    
      FenLeiDetaileModle *model = _dataArr[indexPath.item];
    FenLeiDDetailViewController *vc = [[FenLeiDDetailViewController alloc] init];
    vc.goodsID = model.Id;
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark -------- collectionView --------


#pragma mark -------- －＝－－＝－＝－＝＝－＝－＝＝＝－－＝－＝配置导航栏导航栏
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
//    self.navigationController.navigationBarHidden = NO;
   
    
    UITextField *txtField = [BasePublicCreatUI createTextFielfFrame:CGRectMake(50, 5, kScreen_Width-100, 32)  font:[UIFont systemFontOfSize:15] placeholder:@"搜索商品名称"];
    UIImageView *smallImageView = [BasePublicCreatUI createImageViewFrame:CGRectMake(10, 7, 15, 15)  imageName:@"fenlei_sousuo" color:[UIColor clearColor]];
    [txtField addSubview:smallImageView];
    UIView *leftview= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [leftview addSubview:smallImageView];
    txtField.leftView = leftview;
    txtField.backgroundColor = [UIColor whiteColor];
    txtField.layer.cornerRadius = CGRectGetHeight(txtField.frame)/2.0;
    txtField.clipsToBounds = YES;
    txtField.returnKeyType = UIReturnKeySearch;
    txtField.delegate = self;
    if ([_tureTypeStr isEqualToString:@"search"]) {
        txtField.text = _searchTitle;
    }else {
        txtField.text = @"";
    }
    
    self.navigationItem.titleView  = txtField;
    
    UIBarButtonItem *setItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"liebiao1"] style:(UIBarButtonItemStyleDone) target:self action:@selector(ChangeBtnClick)];
    
    setItem.tintColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = setItem;
    
}

#pragma mark －＝－＝－＝－＝－＝＝－键盘搜索按钮的点击事件
//键盘搜索按钮的点击事件
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (textField.text.length == 0) {
        [MBProgressHUD showText:@"请输入搜索条件"];

    }else {
        _tureTypeStr =@"search";
        _searchTitle =textField.text;
        [textField resignFirstResponder];
        [self GetGoodslist];
    }
 
    
    
    
    
    return YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
-(void)ChangeBtnClick{
    self.collectionView.hidden = !self.collectionView.hidden;
    self.tableView.hidden = !self.tableView.hidden;
}


#pragma mark －＝－＝－＝－＝－获取筛选数据－－－－－－>>>>最右侧筛选
//获取筛选数据
-(void)GetScreenData{

    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic3;
    if ([_tureTypeStr isEqualToString:@"search"]) {
            parameDic3 = @{@"userid":saveDic[@"userid"],@"keyword":_searchTitle,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    }
    else {
       parameDic3 = @{@"userid":saveDic[@"userid"],@"cat_id":_cat_id,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    }
  
    [HttpRequest postWithURLString:POST(Shop_GetScreen) parameters:parameDic3 success:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        if ([[responseObject objectForKey:@"ret"] integerValue] != 200) {
            
        }else{
            NSMutableArray *brandArr = [[responseObject objectForKey:@"data"] objectForKey:@"brand"];
            
            _tempSXArr = [FenleiShaixuanSmallModel mj_objectArrayWithKeyValuesArray:brandArr];
        }
    } failure:^(NSError *error) {
        
    }];
}


#pragma mark －＝－＝－＝－＝－＝－＝－－＝获取商品列表
-(void)GetGoodslist{
    
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    
    [parameDic setObject:[NSString stringWithFormat:@"%@",saveDic[@"userid"]] forKey:@"userid"];
    [parameDic setObject:[NSString stringWithFormat:@"%ld",_page] forKey:@"page"];
    [parameDic setObject:@"20" forKey:@"limit"];
    [parameDic setObject:[Md5Apiway getMD5data:saveDic[@"userid"]] forKey:@"actoken"];
    if ([_tureTypeStr isEqualToString:@"search"]) {
        [parameDic setObject:_searchTitle forKey:@"keyword"];
    }else {
        [parameDic setObject:self.cat_id forKey:@"cat_id"];
    }
    
    if ([self isBlankString:_shopID] == NO) {
        [parameDic setObject:_shopID forKey:@"shop_id"];
    }else {
        
    }
    
    
    
    
   
    
    [HttpRequest postWithURLString:POST(Shop_GetGoodslist) parameters:parameDic success:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        [self.collectionView.mj_header endRefreshing];
        [self.collectionView.mj_footer endRefreshing];
        if (_page == 1) {
            [_dataArr removeAllObjects];
        }
        NSLog(@"%@",responseObject);
        
        
        if ([[responseObject objectForKey:@"ret"] integerValue] != 200) {
            [MBProgressHUD showText:@"数据请求错误"];
            return ;
        }
      
        
        _dataArr22 = [FenLeiDetaileModle mj_objectArrayWithKeyValuesArray:[[responseObject objectForKey:@"data"] objectForKey:@"goodslist"]];
           [_dataArr addObjectsFromArray:_dataArr22.mutableCopy];
        
        [self.collectionView reloadData];
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
    }];

}

//判断一个字符串是否为空
- (BOOL) isBlankString:(NSString *)string {
    
    if (string == nil || string == NULL) {
        
        return YES;
        
    }
    
    if ([string isKindOfClass:[NSNull class]]) {
        
        return YES;
        
    }
    
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        
        return YES;
        
    }
    
    return NO;
    
}

@end
